
import React from 'react'
import './MyAddressList.css'
import { inject, observer } from 'mobx-react'
import { withRouter } from 'react-router-dom'
@withRouter
@inject('address')
@observer
class List extends React.Component {
    constructor() {
        super()
        this.state = {

        }
    }
    selectthisAddress(address) {
        // let { selectAddress } = this.props
        let obj = {
            adcode: "510107",
            area: "36931.310477",
            distance: "0",
            id: "B0FFHOL8UW",
            location: "104.067290,30.546047",
            name: address.receipt_address,
            type: "120201",
        }
        console.log(this.props)

        this.props.address.setAddress(obj)
        this.props.history.push('/Home/Main')
    }
    render() {
        let { addressItem } = this.props
        console.log(addressItem)
        let showItem = []
        if (addressItem.length < 1) {
            showItem = <div className='my-address-list address-info border-bottom-1'>您还没有添加地址，点击新增地址添加常用收货地址~</div>
        } else {
            showItem = addressItem.map((address, index) => {
                return <div className='my-address-list border-bottom-1' key={index} onClick={this.selectthisAddress.bind(this, address)}>
                    <div className='my-user-address'>
                        <span className='my-address-label'>{address.receipt_label}</span>
                        <span className='nowraptext address-info'>{address.receipt_address}</span>
                    </div>
                    <div className='my-user-info'>
                        <span>{address.receipt_people}</span>
                        <span>{address.receipt_sex}</span>
                        <span>{address.receipt_phone}</span>
                    </div>
                </div>
            })

        }
        return (
            /* html */

            <div>
                { showItem}
            </div>
        )
    }
}

export default List